home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_UDELxntp.idb / usr / freeware / src / xntp-3.4o-export / lib / humandate.c.z / humandate.c
C/C++ Source or Header  |  1998-01-21  |  1KB  |  62 lines

  1. /*
  2.  * humandate - convert an NTP (or the current) time to something readable
  3.  */
  4. #include <stdio.h>
  5.  
  6. #include "ntp_fp.h"
  7. #include "ntp_unixtime.h"
  8. #include "lib_strbuf.h"
  9. #include "ntp_stdlib.h"
  10.  
  11. #ifdef NTP_POSIX_SOURCE
  12. #include <time.h>
  13. #endif
  14.  
  15. static char *months[] = {
  16.         "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  17.         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  18. };
  19. static char *days[] = {
  20.         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
  21. };
  22.  
  23. char *
  24. humandate(ntptime)
  25.     u_long ntptime;
  26. {
  27.     char *bp;
  28.     struct tm *tm;
  29.     time_t sec;
  30.  
  31.     LIB_GETBUF(bp);
  32.     
  33.     sec = ntptime - JAN_1970;
  34.     tm = localtime(&sec);
  35.  
  36.     (void) sprintf(bp, "%s, %s %2d %4d %2d:%02d:%02d",
  37.         days[tm->tm_wday], months[tm->tm_mon], tm->tm_mday,
  38.         1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec);
  39.     
  40.     return bp;
  41. }
  42.  
  43.  
  44. /* This is used in msyslog.c; we don't want to clutter up the log with
  45.    the year and day of the week, etc.; just the minimal date and time.  */
  46.  
  47. char *
  48. humanlogtime()
  49. {
  50.     char *bp;
  51.     time_t cursec = time((time_t *) 0);
  52.     struct tm *tm = localtime(&cursec);
  53.     
  54.     LIB_GETBUF(bp);
  55.     
  56.     (void) sprintf(bp, "%2d %s %02d:%02d:%02d",
  57.         tm->tm_mday, months[tm->tm_mon],
  58.         tm->tm_hour, tm->tm_min, tm->tm_sec);
  59.         
  60.     return bp;
  61. }
  62.